﻿using DevTeam;
using System.Collections.Generic;
using System.Data;

namespace ConfExpert.Forms.ImportWizards
{
    public partial class Bossa_Tip1 : XITopCekiListesi
    {
        int YuklemeId;
        public Bossa_Tip1(int YuklemeId) :
            base(YuklemeId)
        {
            InitializeComponent();

            this.YuklemeId = YuklemeId;
            Init("Bossa Tip1 Çeki Listesi", true);
            this.FileDone += this_FileDone;
        }

        void this_FileDone(DataSet ds, string FileName)
        {
            DataTable dt = ds.Tables[0];

            //dt.Rows.RemoveAt(0);    //ilk satır boş

            DataRowCollection rows = dt.Rows;
            DataColumnCollection cols = dt.Columns;

            Dictionary<string, int> indexes = new Dictionary<string, int>();
            for (int colIndex = 0; colIndex < dt.Columns.Count; colIndex++)
            {
                DataRow dr0 = dt.Rows[0];
                switch (dr0[colIndex].ToStr())
                {
                    case "Design Color": indexes.Add("Article", colIndex); break;
                    case "Customer Article": indexes.Add("CustomerCode", colIndex); break;
                    case "Pieces Nr": indexes.Add("VendorRollId", colIndex); break;
                    case "FULL WIDTH": indexes.Add("Qty", colIndex); break;
                    case "Nett.En":
                    case "Nett.M": indexes.Add("WidthUsable", colIndex); break;
                    //case "Our OC No.": indexes.Add("OrderConfirmNo", colIndex); break;
                    //case "Your PO Ref.":
                    //    if (!indexes.ContainsKey("PO"))
                    //        indexes.Add("PO", colIndex);
                    //    break;
                    //case "Your PO Date": indexes.Add("PODate", colIndex); break;
                    //case "Customer Art.Ref.": indexes.Add("CustomerCode", colIndex); break;
                    //case "Invoice No.": indexes.Add("InvoiceNo", colIndex); break;
                    //case "Invoice Date": indexes.Add("InvoiceDate", colIndex); break;
                    //case "Package No.": indexes.Add("KoliNo", colIndex); break;
                    //case "HS Code": indexes.Add("GumrukRefNo", colIndex); break;
                }
            }

            for (int i = 1; i < dt.Rows.Count; i++)
            {
                DataRow dr = rows[i];
                string article = dr[indexes["Article"]].ToString();
                if (Article.Select("Article='" + article + "'").Length == 0)
                {
                    DataRow drArticle = Article.NewRow();
                    drArticle["Article"] = article;
                    drArticle["CustomerCode"] = dr[indexes["CustomerCode"]];
                    Article.Rows.Add(drArticle);
                }
                DataRow drRoll = Roll.NewRow();
                drRoll["Article"] = article;
                drRoll["VendorRollId"] = dr[indexes["VendorRollId"]];
                drRoll["Qty"] = dr[indexes["Qty"]];
                if (dr[indexes["WidthUsable"]].ToStr() != string.Empty)
                    drRoll["WidthUsable"] = dr[indexes["WidthUsable"]];
                //drRoll["PackingListNo"] = dr[indexes["PackingListNo"]];
                //drRoll["PO"] = dr[indexes["PO"]];
                //drRoll["PODate"] = dr[indexes["PODate"]];                
                //drRoll["InvoiceNo"] = dr[indexes["InvoiceNo"]];
                //drRoll["InvoiceDate"] = dr[indexes["InvoiceDate"]];
                //drRoll["KoliNo"] = dr[indexes["KoliNo"]];
                //drRoll["GumrukRefNo"] = dr[indexes["GumrukRefNo"]];

                Roll.Rows.Add(drRoll);
            }
        }

    }
}
